package com.cdut.logistics.action.datacentre;

import java.util.ArrayList;
import java.util.List;

import com.cdut.logistics.intercepter.system.AuthorityIntercepter;
import com.cdut.logistics.model.dao.datacentre.Dept;
import com.cdut.logistics.service.impl.datacentre.DeptImpl;
import com.cdut.logistics.service.interf.datacentre.DeptService;
import com.jfinal.aop.Before;
import com.jfinal.core.Controller;
import com.jfinal.plugin.activerecord.Record;

/**  
 * @ClassName: DeptController  
 * @Description: 部门管理控制类
 * @author wxt.xia
 * @date 2018年1月26日 下午3:28:25    
 */
//@Before(AuthorityIntercepter.class)
public class DeptController extends Controller {
	
	private DeptService deptService = new DeptImpl();
	/**
	 * 
	 * @Title: query  
	 * @Description: 根据部门名称查询部门
	 * @author wxt.xia
	 * @param json
	 * @throws
	 */
	public void query(){
		/*
		 * 解析json
		 */
		String name = getPara("dept_name")+"%";
		List<Record> deptList = new ArrayList<Record>();
		try {
			deptList = deptService.query(name);
			System.out.println(deptList.size());
		} catch (Exception e) {
			// TODO: handle exception
		}
		
		renderJson(deptList);
		
	}
	
	/**
	 * 
	 * @Title: add  
	 * @Description: 新增部门
	 * @author wxt.xia
	 * @throws
	 */
	public void add(){
		/*
		 * 解析json
		 */
		
		//下面是测试数据，id需设置为自增长
		Dept dept = new Dept();
		dept.set("school_id", 21);
		dept.set("name", "教导处");
		
		try {
			deptService.add(dept);
		} catch (Exception e) {
			
		}
	}
	
	/**
	 * 
	 * @Title: form  
	 * @Description: 修改信息
	 * @author wxt.xia
	 * @throws
	 */
	public void modify(){
		/*
		 * 解析json
		 */
		Dept dept = new Dept();
		dept.set("name", "后勤");
		dept.set("id", 1);
		try {
			deptService.modify(dept);
		} catch (Exception e) {
			
		}
	}
	
	/**
	 * 
	 * @Title: remove  
	 * @Description: 删除部门
	 * @author wxt.xia
	 * @throws
	 */
	public void remove(){
		int id = 1;
		try {
			deptService.remove(id);
		} catch (Exception e) {
			
		}
	}
}
